import java.util.ArrayList;
import java.util.List;

public class StringExtractor {

    public static List<String> extractStrings(String sourceCode) {
        List<String> strings = new ArrayList<>();
        StringBuilder currentString = new StringBuilder();
        boolean inString = false;
        boolean escaped = false;

        for (int i = 0; i < sourceCode.length(); i++) {
            char ch = sourceCode.charAt(i);

            if (!inString) {
                if (ch == '"') {
                    inString = true;
                }
            } else {
                if (escaped) {
                    // Add the escaped character to the current string
                    currentString.append(ch);
                    escaped = false;
                } else if (ch == '\\') {
                    // Set the escaped flag for the next character
                    escaped = true;
                } else if (ch == '"') {
                    // End of the current string, add it to the list
                    strings.add(currentString.toString());
                    currentString.setLength(0); // Clear the StringBuilder for the next string
                    inString = false;
                } else {
                    // Regular character, add it to the current string
                    currentString.append(ch);
                }
            }
        }

        // Check for unclosed strings
        if (inString && currentString.length() > 0) {
            throw new IllegalArgumentException("Unclosed string in the source code");
        }

        return strings;
    }

    public static void main(String[] args) {
        String sourceCode = "一般学习一门编程语言的时候，基本上第一个程序是输出\\\"Hello World!\\\"";
        List<String> extractedStrings = extractStrings(sourceCode);

        for (String str : extractedStrings) {
            System.out.println(str);
        }
    }
}